package b_workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;
import utils.RabbitMQUtils;


public class Producer {
    @Test
    public void sendMessage() throws Exception {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("hello", false, false, false, null);
        for (int i = 1; i <= 100; i++) {
            channel.basicPublish("", "hello", null, ("hello rabbitmq workqueue--"+i).getBytes());
        }
        //关闭通道和连接
        RabbitMQUtils.closeChannelAndConnection(channel, connection);
        System.out.println("消息发送成功");
    }
}